package com.fhz.day005;

import android.Manifest;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.tbruyelle.rxpermissions2.RxPermissions;

import javax.inject.Inject;

import dagger.hilt.android.AndroidEntryPoint;
import io.reactivex.functions.Consumer;


@AndroidEntryPoint
public class MainActivity extends AppCompatActivity implements ImageLoader.MyListener {

    private static final String TAG = "feng";

    @Inject
    User user;


    private RxPermissions permissions = new RxPermissions(this);

//    @Inject
//    @Named("sutdent")
//    Person student;

    @Inject
    @Teach
    Person teacher;
    private Button send;
    private ImageView image;

    //    private User user; //普通用法
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        user = new User(); //普通用法



        permissions.request(new String[]
                {Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE})
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        Log.i(TAG, "accept: "+aBoolean);
                    }
                });

//        user.setName("小明");
        Log.i(TAG, "onCreate: " + user.getName());

//        student.eat();
        teacher.eat();

        ACache aCache = ACache.get(this);
        aCache.put("name", "小明");

        String name = aCache.getAsString("name");
        Log.i(TAG, "onCreate: " + name);


        initView();
        ImageLoader.getInstance().setMyListener(this);
    }

    @Override
    public void load(Bitmap bitmap) {
        image.setImageBitmap(bitmap);
    }

    public void send(View view) {
        ImageLoader.getInstance().loading("http://www.qubaobei.com/ios/cf/uploadfile/132/9/8289.jpg");
    }

    private void initView() {
        send = (Button) findViewById(R.id.send);
        image = (ImageView) findViewById(R.id.image);
    }
}